package com.qf.dao.impl;

import com.qf.dao.UsersDao;
import com.qf.dao.UsersDao2;
import com.qf.entity.Users;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

/**
 * 2019/10/9
 * Administrator
 * springboot1009
 * 面向对象面向君  不负代码不负卿
 */
@Repository
public class UserDaoImpl implements UsersDao2 {

    @Resource
    private JdbcTemplate jdbcTemplate;

    @Override
    public List<Users> getall() {

        List<Users> usersList = jdbcTemplate.query("select * from users", new RowMapper<Users>() {
            @Override
            public Users mapRow(ResultSet resultSet, int i) throws SQLException {
                Users users = new Users();
                users.setUserid(resultSet.getInt("userid"));
                users.setUsername(resultSet.getString("username"));
                users.setBirthday(resultSet.getDate("birthday"));
                return users;
            }
        });
        return usersList;
    }
}
